#include <stdio.h>
#include <string.h>
char  c[32];
char *fun(int m, int n)
{
	int i = 0, j = 0, a[32];
	char b[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }, *p;
	do
	{
		a[i] = m%n;
		/**********found**********/
		m = m/n;
		i++;
		/**********found**********/
	} while (m);
	for (--i; i >= 0; --i)
	{
		n = a[i];
		/**********found**********/
		c[j++] =b[n];
	}
	c[j] = 0;
	p = c;
	return p;
}

void main()
{
	int m, n;
	char s[32];
	scanf("%d %d", &m, &n);
	strcpy(s, fun(m, n));
	printf("%s\n", s);
}
